<?php

class User_LostPasswordController extends Zend_controller_Action
{
    public function indexAction()
    {
        $this->view->form = new Model_Form_LostPassword();
    }

    public function sendInstructionsAction()
    {
        $request = $this->getRequest();

        if (!$request->isPost()) {
            return $this->_forward('index');
        }

        $form = new Model_Form_LostPassword();

        if (!$form->isValid($request->getPost())) {
            $this->view->form = $form;
            return $this->render('index');
        }

        // Sends a mail with information to the requesting user
        $lostPassword = new Model_LostPassword();
        $lostPassword->email = $form->getValue('email');
        $lostPassword->sendLostPasswordInstructions();

        $form->setDescription('Lost password instructions sent !');
        $this->view->form = $form;

        return $this->render('index');
    }
}
